<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title>Aloha Editor command subscript tests</title>
	<!-- include qunit -->
	<link rel="stylesheet" href="../../vendor/qunit.css" type="text/css"/>

	<script type="text/javascript" src="../../vendor/qunit.js"></script>

	<script src="../../../lib/require.js" ></script>
	<!-- include jquery -->
	<script	src="../../../lib/vendor/jquery-1.7.2.js" ></script>
	<script type="text/javascript" src="../../vendor/jquery.simulate.js"></script>
	<script>
        require.config({
		    baseUrl: "../"
        });
		var Aloha = {
			settings: {
				jQuery: $,
				baseUrl: '../../../lib'
			}
		};
	</script>

	<!-- include aloha -->
	<script src="../../../lib/aloha.js" ></script>

	<!-- inject into testswarm -->
	<script type="text/javascript" src="../../vendor/swarminject.js"></script>
	<script>
		// load command test suite
		require( ['commandtest'] );
	</script>
	<style type="text/css">
		.aloha-editable ol li { list-style-type: decimal; margin: 1.5em; }
		.aloha-editable ol li ol li{ list-style-type: decimal; margin: 2em; }
	</style>
	<link rel="stylesheet" href="../commandtest.css" type="text/css"/>
</head>
<body>
	<!-- include the tests -->
	<script>
	var tests = {
			defaultValue: '',
			defaultCommand: 'subscript',
			defaultAttributes: [ 'subscript' ],
			tests: [		        
					{  	start: 'fo[o<sub>b]ar</sub>baz',
					   	indetermResult: true,
					   	stateResult: false
					},
					{  	start: 'foo<sub>ba[r</sub>b]az',
					   	indetermResult: true,
					   	stateResult: false
					},
					{  	start: 'fo[o<sub>bar</sub>b]az',
					   	indetermResult: true,
					   	stateResult: false
					},
					{  	start: 'foo[<sub>b]ar</sub>baz',
					   	indetermResult: false,
					   	stateResult: true
					},
					{  	start: 'foo<sub>ba[r</sub>]baz',
					   	indetermResult: false,
					   	stateResult: true
					},
					{  	start: 'foo[<sub>bar</sub>]baz',
					   	indetermResult: false,
					   	stateResult: true
					},
					{  	start: 'foo<sub>[bar]</sub>baz',
					   	indetermResult: false,
					   	stateResult: true
					},
					{  	start: 'foo{<sub>bar</sub>}baz',
					   	indetermResult: false,
					   	stateResult: true
					},

          // specific to the context of subscript & superscript
					{  	start: "<sub>fo[o</sub><sup>b]ar</sup>",
					   	indetermResult: true,
					   	stateResult: false 
					},
          {  	start: "<sub>fo[o</sub><span style=vertical-align:sub>b]ar</span>",
					   	indetermResult: true,
					   	stateResult: false 
					},
          {  	start: "foo<span style=vertical-align:top>[bar]</span>baz",
					   	indetermResult: false,
					   	stateResult: false 
					},
          {  	start: "<sub>fo[o</sub><span style=vertical-align:top>b]ar</span>",
					   	indetermResult: true,
					   	stateResult: false 
					},
          
					{  	start: 'foo[bar]baz',
              execResult: 'foo<sub>[bar]</sub>baz'
          },
          {  	start: 'foo<sub>[bar]</sub>baz',
              execResult: 'foo[bar]baz'
          },
					{  	start: 'foo<sub>[bar</sub>]baz',
              execResult: 'foo[bar]baz' 
          },
					{  	start: 'foo<sub>b[ar</sub>]baz',
              execResult: 'foo<sub>b</sub>[ar]baz' 
          },
					{  	start: 'foo<sub>bar[</sub>b]az',
              execResult: 'foo<sub>bar[b]</sub>az'
          },
					{  	start: 'foo<sub>bar[</sub>b]az',
              execResult: 'foo<sub>bar[b]</sub>az' 
          },
					{  	start: 'foo[]bar',
              execResult: 'foo[]bar' 
          },
					{  	start: '<sub>foo[]bar</sub>',
              execResult: '<sub>foo[]bar</sub>' 
          },
          {   exclude: ['webkit', 'msie7.0', 'msie8.0'],	
              start: '<span>foo</span>{}<span>bar</span>',
              execResult: '<span>foo</span>{}<span>bar</span>' 
          },
          {   include: ['webkit', 'msie7.0', 'msie8.0'],	
              start: '<span>foo</span>{}<span>bar</span>',
              execResult: '<span>foo[]</span><span>bar</span>' 
          },
          // Note: Following test also fails to run on IE9.
          {   exclude: ['webkit', 'msie'], 	
					  	start: '<span>foo[</span><span>]bar</span>',
              execResult: '<span>foo[</span><span>]bar</span>' 
          },
					{  	start: 'foo[bar<b>bam]baz</b>',
              execResult: 'foo<sub>[bar</sub><b><sub>bam]</sub>baz</b>' 
          },
          // Fragments with contenteditable false are not selected in IE 7 & 8.
          {   exclude: [ 'msie8.0', 'msie7.0'],	
					  	start: 'foo<span contenteditable=false>[bar]</span>baz',
					   	execResult: 'foo<span contenteditable=false>[bar]</span>baz' 
					},
          {   exclude: [ 'msie8.0', 'msie7.0'],	
					  	start: 'fo[o<span contenteditable=false>bar</span>b]az',
					   	execResult: 'fo<sub>[o</sub><span contenteditable=false>bar</span><sub>b]</sub>az' 
					},
          {   exclude: ['msie8.0', 'msie7.0'],	
					  	start: 'foo<span contenteditable=false>ba[r]</span>baz',
					   	execResult: 'foo<span contenteditable=false>ba[r]</span>baz' 
					},
          {   exclude: ['webkit', 'msie8.0', 'msie7.0'],	
					  	start: 'fo[o<span contenteditable=false>b]ar</span>baz',
					   	execResult: 'fo<sub>[o</sub><span contenteditable=false>b]ar</span>baz' 
					},
					{  	start: 'fo[<sub>o</sub><span contenteditable=false>bar</span><sub>b</sub>]az',
					   	execResult: 'fo[o<span contenteditable=false>bar</span>b]az' 
					},
					{  	start: '<span contenteditable=false>foo<span contenteditable=true>[bar]</span>baz</span>',
					   	execResult: '<span contenteditable=false>foo<span contenteditable=true><sub>[bar]</sub></span>baz</span>' 
					},
          // Following 4 test cases were excluded from Webkit,
          // as it has a bug in range selection implementation.
          // There's an opened ticket for this in Webkit's bugzilla - https://bugs.webkit.org/show_bug.cgi?id=80763
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
					  	start: '<span contenteditable=false>fo[o<span contenteditable=true>bar</span>b]az</span>',
					   	execResult: '<span contenteditable=false>fo[o<span contenteditable=true><sub>bar</sub></span>b]az</span>' 
					},
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
					  	start: '<span contenteditable=false>foo<span contenteditable=true>ba[r</span>b]az</span>',
					   	execResult: '<span contenteditable=false>foo<span contenteditable=true>ba<sub>[r</sub></span>b]az</span>' 
					},
          {   exclude: ["webkit", "msie8.0", "msie7.0"],	
					  	start: '<span contenteditable=false>fo[o<span contenteditable=true>b]ar</span>baz</span>',
              execResult: '<span contenteditable=false>fo[o<span contenteditable=true><sub>b]</sub>ar</span>baz</span>' 
					},
          {   exclude: ['msie8.0', 'msie7.0'],	
					  	start: '<table><tbody><tr><td>foo<td>b[a]r<td>baz</table>',
					   	execResult: '<table><tbody><tr><td>foo<td>b<sub>[a]</sub>r<td>baz</table>' 
					},
          {   exclude: ['mozilla', 'msie'],	
					  	start: '<table><tbody><tr data-start=1 data-end=2><td>foo<td>bar<td>baz</table>',
					   	execResult: '<table><tbody><tr><td>foo<td><sub>[bar</sub><td>}baz</table>' 
					},
					{  	exclude: ['mozilla', 'msie'],	
					  	start: '<table><tbody><tr data-start=0 data-end=2><td>foo<td>bar<td>baz</table>',
					   	execResult: '<table><tbody><tr><td><sub>[foo</sub><td><sub>bar</sub><td>}baz</table>' 
					},
					{  	exclude: ['mozilla', 'msie'],	
					  	start: '<table><tbody data-start=0 data-end=1><tr><td>foo<td>bar<td>baz</table>',
					   	execResult: '<table><tbody><tr><td><sub>[foo</sub><td><sub>bar</b><td><sub>baz</sub></table>}' 
					},
					{  	exclude: ['mozilla', 'msie'],	
					  	start: '<table data-start=0 data-end=1><tbody><tr><td>foo<td>bar<td>baz</table>',
					   	execResult: '{<table><tbody><tr><td><sub>foo</sub><td><sub>bar</sub><td><sub>baz</sub></table>}' 
					},
          {   exclude: ['msie8.0', 'msie7.0'],
              start: '{<table><tr><td>foo<td>bar<td>baz</table>}',
					   	execResult: '{<table><tr><td><sub>foo</sub><td><sub>bar</sub><td><sub>baz</sub></table>}' 
					},
					{  	start: 'foo<sub>[bar]</sub>baz',
					   	execResult: 'foo[bar]baz' 
					},
					{  	start: 'foo<sub>bar</sub>[baz]',
					   	execResult: 'foo<sub>bar[baz]</sub>' 
					},
					{  	start: '[foo]<sub>bar</sub>baz',
					   	execResult: '<sub>[foo]bar</sub>baz' 
					},
					{  	start: '<sub>foo</sub>[bar]<sub>baz</sub>',
					   	execResult: '<sub>foo[bar]baz</sub>' 
					},
					{  	start: 'foo[<sub>bar</sub>]baz',
					   	execResult: 'foo[bar]baz' 
					},
					{  	start: 'foo[<sub>bar]</sub>baz',
					   	execResult: 'foo[bar]baz' 
					},
					{  	start: 'foo<sub>[bar</sub>]baz',
					   	execResult: 'foo[bar]baz' 
					},
          {   exclude: ["webkit", "msie"],	
					  	start: 'foo{<sub></sub>}baz',
					   	execResult: 'foo{<sub></sub>}baz' 
					},
          { exclude: ["msie7.0", "msie8.0"], //this test freezes both IE 7/8 in my local setup
            start: '<p>[foo</p><p>bar]</p><sub><p>baz</sub></b>',
						indetermStart: false,
						stateStart: false,
            execResult: '<p><sub>[foo</sub></p><p><sub>bar]</sub></p><sub><p>baz</sub></b>', 
						indetermResult: false,
						stateResult: true   
					},
					{  	start: 'foo [bar <sub>baz] bam</sub> bom',
						indetermStart: true,
						stateStart: false,
					   	execResult: 'foo <sub>[bar baz] bam</sub> bom', 
						indetermResult: false,
						stateResult: true,
					   	execToggle: 'foo [bar baz]<sub> bam</sub> bom', 
						indetermToggle: false,
						stateToggle: false
					},
					{  	start: 'foo <sub>[bar baz] bam</sub> bom',
						stateStart: true,
					   	execResult: 'foo [bar baz]<sub> bam</sub> bom', 
						stateResult: false   
					},
          /* In the following two commented tests,
             though the operation is performed as intended,
             resulting output have range inconsistencies across all browsers.
             Please review and suggest removal or possible modifications.

					{  	start: '<sub><p>foo[<b>bar</b>}</p><p>baz</p></sub>',
						stateStart: true,
					   	execResult: '<p><sub>foo</sub><b>[bar]</b></p><p><sub>baz</sub></p>', 
						stateResult: false   
					},
					{  	start: '<sub><p>foo</p></sub><b>[bar</b>}<sub><p>baz</p></sub>',
						stateStart: false,
					   	execResult: '<sub><p>foo</p><b>[bar]</b><p>baz</p></sub>', 
						stateResult: true,   
					   	execToggle: '<p><sub>foo</sub></p><b>[bar]</b><p><sub>baz</sub></p>', 
						stateToggle: false   
					},
          */
					{  	start: 'foo bar <sub>baz [bam</sub> bom] bus',
						indetermStart: true,
						stateStart: false,
					   	execResult: 'foo bar <sub>baz [bam bom]</sub> bus', 
						indetermResult: false,
						stateResult: true   
					},
          {  exclude: ['msie7.0'],  
             start: '<sub id=purple>bar [baz] qoz</sub>',
             stateStart: true,
					   execResult: '<span id=purple><sub>bar </sub>[baz]<sub> qoz</sub></span>', 
             stateResult: false   
					},
          // IE 7.0 gives a different markup for the following 3 test cases.
          // However, since the result is visibly same,
          // I added a test with the alternate markup.
          {   exclude: ['msie7.0'],
					  	start: '<b><sub>foo</sub></b>[bar]<b><sub>baz</sub></b>',
					   	execResult: '<sub><b>foo</b>[bar]<b>baz</b></sub>'
					},
          {   include: ['msie7.0'],
					  	start: '<b><sub>foo</sub></b>[bar]<b><sub>baz</sub></b>',
              execResult: '<b><sub>foo</sub></b><sub>[bar]</sub><b><sub>baz</sub></b>'
					},
          {   exclude: ['msie7.0'],
					  	start: '<sub>foo</sub>[bar]<b><sub>baz</sub></b>',
					   	execResult: '<sub>foo[bar]<b>baz</b></sub>'
					},
          {   include: ['msie7.0'],
					  	start: '<sub>foo</sub>[bar]<b><sub>baz</sub></b>',
              execResult: '<sub>foo[bar]</sub><b><sub>baz</sub></b>'
					},
          {   exclude: ['msie7.0'],
					  	start: '<font color=blue face=monospace><sub>foo</sub></font>[bar]',
					   	execResult: '<sub><font color=blue face=monospace>foo</font>[bar]</sub>'
					},
          {   include: ['msie7.0'],
					  	start: '<font color=blue face=monospace><sub>foo</sub></font>[bar]',
              execResult: '<font color=blue face=monospace><sub>foo</sub></font><sub>[bar]</sub>'
					},

          // specific to the context of subscript & superscript
					{  	start: "foo<sub>[bar]</sub>baz",
					   	execResult: "foo[bar]baz"
					},
          {  	start: "foo<sub>b[a]r</sub>baz",
					   	execResult: "foo<sub>b</sub>[a]<sub>r</sub>baz"
					},
          {  	start: "foo<sup>[bar]</sup>baz",
              execResult: "foo<sub>[bar]</sub>baz"
					},
          {  	start: "foo<sup>b[a]r</sup>baz",
              execResult: "foo<sup>b</sup><sub>[a]</sub><sup>r</sup>baz"
					},
          {  	start: "foo<span style=vertical-align:sub>[bar]</span>baz",
					   	execResult: "foo<sub><span style=\"vertical-align:sub\">[bar]</span></sub>baz"
					},
          {  	start: "foo<span style=vertical-align:super>[bar]</span>baz",
					   	execResult: "foo<sub><span style=\"vertical-align:super\">[bar]</span></sub>baz"
					},
          {  	start: "foo<sub><sub>[bar]</sub></sub>baz",
					   	execResult: "foo[bar]baz"
					},
          {  	start: "foo<sub><sub>b[a]r</sub></sub>baz",
					   	execResult: "foo<sub>b</sub>[a]<sub>r</sub>baz"
					},
          {  	start: "foo<sub>b<sub>[a]</sub>r</sub>baz",
					   	execResult: "foo<sub>b</sub>[a]<sub>r</sub>baz"
					},
          {  	start: "foo<sup><sup>[bar]</sup></sup>baz",
              execResult: "foo<sub>[bar]</sub>baz"
					},
          {  	start: "foo<sup><sup>b[a]r</sup></sup>baz",
              execResult: "foo<sup>b</sup><sub>[a]</sub><sup>r</sup>baz"
					},
          {  	start: "foo<sup>b<sup>[a]</sup>r</sup>baz",
              execResult: "foo<sup>b</sup><sub>[a]</sub><sup>r</sup>baz"
					},
          {  	start: "foo<sub><sup>[bar]</sup></sub>baz",
					   	execResult: "foo<sub>[bar]</sub>baz"
					},
          {  	start: "foo<sub><sup>b[a]r</sup></sub>baz",
              execResult: "foo<sup>b</sup><sub>[a]</sub><sup>r</sup>baz"
					},
          {  	start: "foo<sub>b<sup>[a]</sup>r</sub>baz",
					   	execResult: "foo<sub>b[a]r</sub>baz"
					},
          {  	start: "foo<sup><sub>[bar]</sub></sup>baz",
					   	execResult: "foo<sub>[bar]</sub>baz"
					},
          {  	start: "foo<sup><sub>b[a]r</sub></sup>baz",
					   	execResult: "foo<sub>b[a]r</sub>baz"
					},
          {  	start: "foo<sup>b<sub>[a]</sub>r</sup>baz",
              execResult: "foo<sup>b</sup><sub>[a]</sub><sup>r</sup>baz"
					},
          {  	start: "foo<sup>b<sub>[a]</sub>r</sup>baz",
              execResult: "foo<sup>b</sup><sub>[a]</sub><sup>r</sup>baz"
					}
			]
	}
	</script>
	<h1 id="qunit-header">Aloha Editor command subscript tests</h1>
	<h2 id="qunit-banner"></h2>
	<div id="qunit-testrunner-toolbar"></div>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests"></ol>
	<div id="qunit-fixture"></div>
	<div id="edit" style="margin:20px; border:1px solid #000000;"></div>
	<div id="logBody"></div>
	</div>
</body>
</html>
